package com.sh4.controller;


import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.sh4.entity.Permission;
import com.sh4.service.PermissionService;

import net.sf.json.JSONObject;

@RestController
@RequestMapping(value="permission")
public class PermissionController {

	@Autowired
	PermissionService permissionmService;
	
	
	@RequestMapping(value="/list",method=RequestMethod.POST)
	public Map<String , Object> getList(@RequestBody JSONObject params, @RequestParam int pageSize , @RequestParam int pageNo){
		
		return permissionmService.list(pageNo, pageSize, params);
	}
	
	@RequestMapping(value="/",method=RequestMethod.POST)
	public Permission savePermission(@RequestBody Permission e) {
		
		permissionmService.savePermission(e);
		
		return e;
	}
	
	@RequestMapping(value="/",method=RequestMethod.DELETE)
	public Permission deletePermission(@RequestBody Permission e) {
		
		permissionmService.deletePermission(e);
		
		return e;
	}
	
	@RequestMapping(value="/savePermissionResource",method=RequestMethod.POST)
	public List<String> savePermissionResource(@RequestParam String permissionId,@RequestBody List<String> menuIds) {
		
		permissionmService.savePermissionResource(menuIds, permissionId);
		
		return menuIds;
	}
	
	@RequestMapping(value="/getPermissionResource",method=RequestMethod.GET)
	public List<String> getPermissionResource(@RequestParam String permissionId) {
		
		return permissionmService.getPermissionResource(permissionId);
	}
}
